package com.yunji.product.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunji.common.base.BaseDaoImpl;
import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.product.dao.IProductUnitDao;
import com.yunji.product.domain.ProductUnitDO;
import com.yunji.product.mapper.ProductUnitMapper;
import com.yunji.product.params.UnitParam;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProductUnitDaoImpl extends BaseDaoImpl<ProductUnitMapper, ProductUnitDO> implements IProductUnitDao {
    @Override
    public List<ProductUnitDO> search(UnitParam param) {
        return list(new LambdaQueryWrapper<ProductUnitDO>()
                .eq(BeanUtils.isNotNull(param.getUnitId()), ProductUnitDO::getUnitId, param.getUnitId())
                .like(BeanUtils.isNotNull(param.getUnitName()), ProductUnitDO::getUnitName, param.getUnitName())
                .orderByAsc(ProductUnitDO::getSort));
    }
}
